package com.dgt.trade.controller;

import com.dgt.trade.entitys.News;
import com.dgt.trade.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;

@Controller
@RequestMapping(value = "/news")
public class NewsController extends  BaseController {

    @Autowired
    NewsService newsService;

    @RequestMapping(value = "/index")
    public ModelAndView selectNewsById(String id){
        ModelAndView view=new ModelAndView();
        if(id == null){
            id="";
        }
        List<News> list=newsService.selectNewsById("%"+id+"%");
        if(list != null){
            if(id == null || id == ""){
                view.getModel().put("list",list);
                view.setViewName("infor_index");
            }else{
                view.getModel().put("list",list);
                view.setViewName("trade/zxyw");
            }
        }else{
            view.setViewName("error/404");
        }
        return view;
    }

}
